package com.hdax.dm.rest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdax.dm.dao.base.DmImageMapper;
import com.hdax.dm.entity.base.DmImage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(path = "/base")
@Api(value = "图片接口",tags = "图片接口")
public class DmBaseRestService {

    @Resource
    private DmImageMapper dmImageMapper;

    @PostMapping(path = "/getImage")
    @ApiOperation(value = "查询图片（根据type和category及商品id）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", required = true),
            @ApiImplicitParam(name = "category", required = true),
            @ApiImplicitParam(name = "targetId", required = true)
    })
    public DmImage getImage(@RequestParam("type")Long type,
                            @RequestParam("category")Long category,
                            @RequestParam("targetId")Long targetId){
        QueryWrapper<DmImage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type",type);
        queryWrapper.eq("category",category);
        queryWrapper.eq("targetId",targetId);
        return dmImageMapper.selectOne(queryWrapper);
    }


    @ApiImplicitParams({})
    @ApiOperation(value = "查询轮播图")
    @PostMapping(path = "/carousel")
    public List<DmImage> carousel(){
        QueryWrapper<DmImage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type",1L);
        queryWrapper.eq("category",1L);
        return dmImageMapper.selectList(queryWrapper);
    }

    //修改图片
    @PostMapping(path = "/updateImg")
    public int updateImg(@RequestBody DmImage dmImage){
        return dmImageMapper.updateById(dmImage);
    }

}
